//==============================================================================
// ReadingFrame.hh
// ----------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
// $Id: $
//------------------------------------------------------------------------------
//
//==============================================================================
//.......1.........2.........3.........4.........5.........6.........7.........8
//

#include "LocalSTL.hh"
#include "Sequence.hh"

#ifndef _READING_FRAME
#define _READING_FRAME

 

//------------------------------------------------------------------------------
// * OpenReadingFrame
//------------------------------------------------------------------------------
//
class OpenReadingFrame{
public:
	int start;
	int length;
	int frame;
	
	// Make length the default way to compare OpenReadingFrames
	friend const bool operator<(const OpenReadingFrame& a,const OpenReadingFrame &b){
 		return(b.length<a.length);
 	};
	
	// KJD This simpler version doesn't work, apparently because the "this" pointer 
	// that is passed in implicitly is volatile by default, yet usage wants it to be 
	// constant.  ???
	// const bool	operator<(const OpenReadingFrame& a){return(length<a.length);};
		
	void Print(ostream &outs){
		outs<<frame<<","<<start<<","<<length<<endl;
	}
};

//------------------------------------------------------------------------------
// * ORFVec
//------------------------------------------------------------------------------
//
class ORFVec : public vector<OpenReadingFrame>{
public:
	void SortByLength(){sort(this->begin(),this->end());};
	void Print(ostream &outs){
		for(int oIdx = 0;oIdx < size();oIdx++){
			(*this)[oIdx].Print(outs);
		}
	};
	
};

//------------------------------------------------------------------------------
// * ReadingFrame
//------------------------------------------------------------------------------
//   
//
class ReadingFrame{
public:

	int  Idx(char c);
	char Decode(char a0,char a1,char a2);
	void DecodeSeq(int start,int frame,Sequence &DNAIn,Sequence &ProteinOut);
	void FindOpenReadingFrames2(Sequence &DNAIn,ORFVec &ORFOut,int minSize,bool IsFwd);
	void FindOpenReadingFrames(Sequence &DNAIn,ORFVec &ORFOut,
								int start,int end,int minSize,bool IsFwd);
	void FindFwdOpenReadingFrames(Sequence &DNAIn,ORFVec &ORFOut,int minSize);
	void FindAllOpenReadingFrames(Sequence &DNAIn,ORFVec &ORFOut,int minSize);
	bool IsStop(char c1,char c2,char c3);
	bool IsStart(char c1,char c2,char c3);

  
  void FindStarts(Sequence &DNAIn,ORFVec &ORFOut,bool IsFwd);
  void FindStops(Sequence &DNAIn,ORFVec &ORFOut,bool IsFwd);

  void FindAllStarts(Sequence &DNAIn,ORFVec &ORFOut);
  void FindAllStops(Sequence &DNAIn,ORFVec &ORFOut);
  

};


#endif
